package com.itwxz.games.controller;

import com.itwxz.common.core.domain.R;
import com.itwxz.games.domain.undercover.UCreateRoomInfo;
import com.itwxz.games.domain.undercover.UIdentity;
import com.itwxz.games.domain.undercover.URoom;
import com.itwxz.games.domain.undercover.UndercoverWord;
import com.itwxz.games.service.UndercoverService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/games/undercover")
public class UndercoverController {
    private final UndercoverService undercoverService;

    @GetMapping("/words")
    public R<UndercoverWord> getWords() {
        UndercoverWord words = undercoverService.getWords();
        return R.ok(words);
    }

    @PostMapping("/create-room")
    public R<URoom> createRoom(@RequestBody UCreateRoomInfo info) {
        URoom URoom = undercoverService.createRoom(info);
        return R.ok(URoom);
    }

    @PostMapping("/create-room/no-owner")
    public R<UIdentity> createRoomNoOwner(@RequestBody UCreateRoomInfo info) {
        UIdentity identity = undercoverService.createRoomNoOwner(info);
        return R.ok(identity);
    }

    @GetMapping("/join-room")
    public R<UIdentity> joinRoom(@RequestParam String roomId) {
        UIdentity uIdentity = undercoverService.joinRoom(roomId);
        return R.ok(uIdentity);
    }

    @GetMapping("/check-room")
    public R<Boolean> checkRoom(@RequestParam String roomId) {
       return undercoverService.checkRoom(roomId);
    }

    @GetMapping("/check-id")
    public R<Boolean> checkRoomAndId(@RequestParam String roomId, @RequestParam String id) {
        return undercoverService.checkRoomAndId(roomId, id);
    }

    @GetMapping("/close-room")
    public R<Boolean> closeRoom(@RequestParam String roomId) {
        return undercoverService.closeRoom(roomId);
    }
}
